package com.example.team.controller;

import com.example.team.entity.VehicleUsage;
import com.example.team.service.IVehicleUsageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 编写者：蓝江富
 * 时间：2023年10月31日15:52:18
 */
@RestController
@Api(tags = "用车管理")
public class VehicleUsageController {
    @Autowired
    private IVehicleUsageService vehicleUsageService;

    @ApiOperation(value = "添加用车记录",
            notes = "成功返回1")
    @RequestMapping("/insertVehicleUsage")
    public int insertVehicleUsage(VehicleUsage vehicleUsage){
        return vehicleUsageService.insertVehicleUsage(vehicleUsage);
    }

    @ApiOperation(value = "删除用车记录",
            notes = "根据id删除")
    @RequestMapping("/deleteVehicleUsage")
    public int deleteVehicleUsage(Integer id){
        VehicleUsage vehicleUsage=new VehicleUsage();
        vehicleUsage.setUsageId(id);
        return vehicleUsageService.deleteVehicleUsage(vehicleUsage);
    }

    @ApiOperation(value = "修改用车记录",
            notes = "根据id修改")
    @RequestMapping("/updateVehicleUsage")
    public int updateVehicleUsage(VehicleUsage vehicleUsage){
        return vehicleUsageService.updateVehicleUsage(vehicleUsage);
    }

    @ApiOperation(value = "查询所有用车信息",
            notes = "成功返回Json")
    @RequestMapping("/getAllVehicleUsage")
    public List<VehicleUsage> getAllVehicleUsage(Integer applicant){
        VehicleUsage vehicleUsage=new VehicleUsage();
        vehicleUsage.setApplicant(applicant);
        return vehicleUsageService.getAllVehicleUsage(vehicleUsage);
    }

    @ApiOperation(value = "查询用车信息",
            notes = "根据applicant查询")
    @RequestMapping("/getVehicleUsage")
    public VehicleUsage getVehicleUsage(Integer applicant){
        VehicleUsage vehicleUsage=new VehicleUsage();
        vehicleUsage.setApplicant(applicant);
        return vehicleUsageService.getVehicleUsage(vehicleUsage);
    }
}
